package com.zxx.pattern.mementoPattern;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;

/**
 * @author zxx on 2021/3/16
 */
public class NoteEditText extends EditText {


    public NoteEditText(Context context) {
        super(context);
    }

    public NoteEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NoteEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public Memoto createMemoto() {
        Memoto memoto = new Memoto();
        //存储文本与光标位置
        memoto.text = getText().toString();
        memoto.cursor = getSelectionStart();
        return memoto;
    }

    public void restore(Memoto memoto) {
        if (memoto != null) {
            setText(memoto.text);
            setSelection(memoto.cursor);
        }
    }

}
